package guda.house.biz.form.bill;

import guda.house.biz.util.PriceUtil;
import guda.house.dal.dataobject.InvoiceLogDO;

import javax.validation.constraints.NotNull;
import java.text.SimpleDateFormat;

/**
 * Created by well on 15/11/16.
 */
public class InvoiceLogEditForm extends InvoiceLogForm{
    @NotNull(message = "不能为空")
    private Long logId;

    public InvoiceLogDO toDO(){
        InvoiceLogDO invoiceLogDO = super.toDO();
        invoiceLogDO.setLogId(logId);
        return invoiceLogDO;
    }

    public void initForm(InvoiceLogDO invoiceLogDO){
        setLogId(invoiceLogDO.getLogId());
        setInvoiceTypeId(invoiceLogDO.getInvoiceTypeId());

        setInvoiceNo(invoiceLogDO.getInvoiceNo());
        setInvoiceCatId(invoiceLogDO.getInvoiceCatId());
        setInvoiceComment(invoiceLogDO.getInvoiceComment());
        setInvoiceSerial(invoiceLogDO.getInvoiceSerial());
        if(invoiceLogDO.getGmtInvoice()!=null) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            setGmtInvoice(simpleDateFormat.format(invoiceLogDO.getGmtInvoice()));
        }
        if(invoiceLogDO.getInvoiceMoney()!=null){
            setInvoiceMoney(PriceUtil.formatCNYNoGroup(invoiceLogDO.getInvoiceMoney()));
        }
    }

    public Long getLogId() {
        return logId;
    }

    public void setLogId(Long logId) {
        this.logId = logId;
    }
}
